﻿using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.IO;

public class PackageA : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
    [MenuItem( "AssetBundleDemo/Package A" )]
    static void CreateAssetBundle()
    {
        Debug.Log( "start" );
        Object[] selects = Selection.GetFiltered( typeof( Object ), SelectionMode.DeepAssets );
        foreach( Object obj in selects )
        {
            //这里建立一个本地测试  
            //注意本地测试中可以是任意的文件，但是到了移动平台只能读取路径StreamingAssets里面的  
            //StreamingAssets是只读路径，不能写入  
            string targetPath = Application.dataPath + "/StreamingAssets/pc/" + obj.name + ".assetbundle";//文件的后缀名是assetbundle和unity都可以  
            //if( BuildPipeline.BuildAssetBundle( obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies ) )
            //{

            //    Debug.Log( obj.name + "is packed successfully!" );
            //}
            //else
            //{
            //    Debug.Log( obj.name + "is packed failly!" );
            //}
        }
        AssetDatabase.Refresh();
    }
}
